<script>
    var ajaxUrl = '<?php echo Yii::app()->createUrl('ajax/xupload') ?>';
    var countImages = '<?php echo count($images); ?>';
</script>
<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/preview.js"></script>
<script type="text/javascript">
    tinyMCE.init({
        mode : "exact",
        elements : "editor",
        theme : "advanced",
        skin : "default",
        width : "81%",
        height : "210",
        invalid_elements: "img, a, script, h1, h2, h3, h4, h5, h6, h7, font, iframe, object",
        theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : false,
        theme_advanced_path : false
    });
</script>
<?php $this->renderPartial('//partials/partnerMenu', array('partner'=>$partner, 'show_tabs'=>1, 'curent'=>'forum', 'advertCode'=>$advertCode, 'cat'=>$cat, 'userIsWork'=>$userIsWork, 'relProfiles'=>$relProfiles, 'errorModel'=>$errorModel, 'subCats'=>$subCats));?> 
<hr/>

<div>
    <span class="date"><?php echo Yii::app()->dateFormatter->format("dd MMMM yyyy года в HH:mm", $model['comDate']); ?></span>&nbsp;
    <span style="color: violet; cursor: pointer"><?php echo !empty($user) ? !empty($user['displayName']) ? $user['displayName'] : $user['login'] : 'Гость'; ?></span>&nbsp; 
    <span style="color: violet; cursor: pointer">Обратиться по нику</span>
    <br/><br/>
        
    <?php if(!empty($user) && ($partner['delegate1'] == $user['userid'] || $partner['delegate2'] == $user['userid']) ) : ?>
        <img style="float:left" src="/images/prettyImg/supUns.jpg"/>
    <?php endif; ?>
        
    <div class="messageText">
        <?php 
        $str = $model['text'];
        while(1) {
            if(preg_match('/ \[quote(\s*|="(.*)")\s*(\s*|date="(.*)")\](.*)\[\/quote\](\s*|\S*)|\[quote /Uxis', $str)) {
                $str = CPartnerkiHelper::printQuotesAndMessage($str);
            } else {
                echo $str;
                break;
            }
        }  ?>
    </div>

    <?php if(!empty($images)) : ?>
        <br/><br/><br/>
        <?php foreach ($images as $comImg) : ?>
            <a href="#" class="big-link" data-reveal-id="com-modal<?php echo $comImg['imgId']; ?>" data-animation="fade">
                <img src="<?php echo Yii::app()->baseUrl.'/images/uploads/comments/'.$comImg['smallImg']; ?>"/>
            </a>     
            <div id="com-modal<?php echo $comImg['imgId']; ?>" class="reveal-modal">
                <img src="<?php echo Yii::app()->baseUrl.'/images/uploads/comments/'.$comImg['bigImg']; ?>"/>
                <a class="close-reveal-modal">&#215;</a>
            </div>
        <?php endforeach; ?>    
    <?php endif; ?>
    <br/><br/>     
    <hr/>
</div>

<?php echo CHtml::errorSummary($model); ?>
<?php echo CHtml::beginForm('', 'post', array('id'=>'form')); ?>
    <br/><br/>
    Текущие изображения. Клик - удалить:
    <div class="inline">
        <?php foreach($images as $comImg) : ?>
            <img style="cursor:pointer" class="loadedImg" src="<?php echo Yii::app()->baseUrl.'/images/uploads/comments/'.$comImg['smallImg']; ?>"/>
        <?php endforeach; ?>
    </div>
    <?php echo CHtml::activeHiddenField($model, 'deletedImg', array('value'=>'1', 'id'=>'deletedImg')); ?>
    <br/><br/>

    <div style="margin-top: 50px; background-color:wheat;" id="commentFileUpload">
        <?php echo CHtml::activeTextArea($model, 'text', array('id'=>'editor')); ?>
        <?php echo CHtml::activeHiddenField($model, 'themeId', array('value'=>$model['themeId'], 'id'=>'themeId')); ?>
        <?php echo CHtml::submitButton('Сохранить изменения', array('class'=>'btn btn-large btn-primary')); ?>
        <a href="" class="btn btn-large btn-primary">Отменить изменения</a>
        <br/>
        <span style="color: gray">JPG, PNG, GIF не более 500КБ</span>   
        <br/><br/>
        <?php Yii::import("xupload.models.XUploadForm"); ?>
        <div id="commentFileUpload">
            <?php $this->widget('xupload.XUpload', array(
                'url' => Yii::app()->createUrl("partner/forum/upload"),
                'model' => new XUploadForm, 
                'attribute' => 'file',
                'showForm' => false,    
                'multiple' => true,
                'options' => array( 
                    'autoUpload' => true, 
                    'maxNumberOfFiles' => !empty($images) ? 5 - count($images) : 5, 
                    'maxFileSize' => 500000,
                    'acceptFileTypes' => "js:/(\.|\/)(jpg|png|gif)$/i",
                ),
                'downloadView'=>'downloadViewOrigin',
                'htmlOptions' => array('id'=>'commentFileUpload'),
            ));  ?>
        </div>
    </div>
<?php echo CHtml::endForm(); ?>